var ret_eg = db.getCollection('estate').aggregate([
    {$group:{_id:{
                  projectUrl:'$projectUrl',
                  projectId:'$projectId',
                  projectName:'$projectName',
                  projectSubName:'$projectSubName',
                  districtName:'$districtName',
                  projectAddress:'$projectAddress',
                  projectUse:'$projectUse',
                  developerName:'$developerName',
                  certDate:'$certDate',
                  preSalePermit:'$preSalePermit',
                  totalRoomNo:'$totalRoomNo',
                  landUseRightNum:'$landUseRightNum',
                  },
                  count:{$sum:1},
                  dups:{$addToSet:'$_id'}}
                  },
    {$match:{count:{$gt:1}}},
    ],{allowDiskUse:true});
ret_eg.forEach(function(doc){
	doc.dups.shift();
	db.getCollection('estate').remove({_id: {$in: doc.dups}});
});

var ret_bd = db.getCollection('building').aggregate([
    {$group:{_id:{
                  districtName:'$districtName',
                  projectName:'$projectName',
                  projectId:'$projectId',
                  blockName:'$blockName',
                  buildingUrl:'$buildingUrl',
                  buildingId:'$buildingId',
                  certDate:'$certDate',
                  preSalePermit:'$preSalePermit',
                  totalRoomNo:'$totalRoomNo',
                  },
                  count:{$sum:1},
                  dups:{$addToSet:'$_id'}}
                  },
    {$match:{count:{$gt:1}}},
    ],{allowDiskUse:true});
ret_bd.forEach(function(doc){
	doc.dups.shift();
	db.getCollection('building').remove({_id: {$in: doc.dups}});
});

var ret_rm = db.getCollection('room').aggregate([
    {$group:{_id:{
                  projectId:'$projectId',
                  blockName:'$blockName',
                  buildingId:'$buildingId',
                  roomNo:'$roomNo',
                  roomUse:'$roomUse',
                  roomUrl:'$roomUrl',
                  roomFloor:'$roomFloor',
                  saleStatus:'$saleStatus',
                  roomArea:'$roomArea',
                  unitPrice:'$unitPrice',
                  },
                  count:{$sum:1},
                  dups:{$addToSet:'$_id'}}
                  },
    {$match:{count:{$gt:1}}},
    ],{allowDiskUse:true});
ret_rm.forEach(function(doc){
	doc.dups.shift();
	db.getCollection('room').remove({_id: {$in: doc.dups}});
});